<template>
  <div>
    <h1>sonA</h1>
    name:
    <input type="text" v-model="name" /><br />
    age:
    <input type="text" v-model="age" /><br />
    <button @click="collection">收集数据</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      name: "",
      age: 18,
    };
  },
  created() {
    console.log(this);
  },
  methods: {
    collection() {
      console.log(this.name);
      console.log(this.age);
      // 收集到数据目的 {name：‘’，age:""}
      // 收集到该对象  把该对象从 sonA ---parentA
      const item = {
        name: this.name,
        age: this.age,
      };
      console.log(item);
      this.$emit("addItem", item);
      //   this.$emit(事件名，传递的参数)
    },
  },
};
</script>

<style lang="scss" scoped>
</style>